//package com.zl.zsk.service.rabbitmq;
//
//import com.zl.zsk.config.RabbitMqConfig;
//import com.zl.zsk.pojo.bo.RabbitMQMessage;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.AmqpException;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.core.MessageDeliveryMode;
//import org.springframework.amqp.core.MessagePostProcessor;
//import org.springframework.amqp.core.MessageProperties;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//
///**
// * @author lxb
// * @version 1.0.0
// * @desc:
// * @date 2020-03-18 17:15
// */
//@Component
//@Slf4j
//public class BusinessProvider {
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    @Value("${mq.second.kill.dead.exchange}")
//    private String deadExchange;
//
//    @Value("${mq.second.kill.dead.routing.key}")
//    private String deadRoutingKey;
//
//
//    public void sendMsg(String msg){
//        rabbitTemplate.convertSendAndReceive(RabbitMqConfig.LXB_FANOUT_EXCHANGE, "", msg);
//    }
//
//    public void sendSecondKillMsg(){
////        RabbitMQMessage rabbitMQMessage = new RabbitMQMessage();
////        rabbitMQMessage.setMessageId(111L);
////        rabbitMQMessage.setMessage("这是测试秒杀");
////        rabbitMQMessage.setFlag("second kill");
////        rabbitMQMessage.setTime(new Date().getTime());
//        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//        log.info("准备发送rabbitmq消息，超时为20s");
//        rabbitTemplate.convertAndSend(deadExchange,deadRoutingKey,"失败与否", new MessagePostProcessor() {
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                MessageProperties mp=message.getMessageProperties();
//                mp.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
//                mp.setHeader(AbstractJavaTypeMapper.DEFAULT_CONTENT_CLASSID_FIELD_NAME,RabbitMQMessage.class);
//                mp.setExpiration("5000");//超时时间 5s
//                return message;
//            }
//        });
//        log.info("生产者结束");
//    }
//}
